//
//  NSDate+LCYCurrentDate.m
//  IMByLinkUs
//
//  Created by lcy on 16/1/19.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "NSDate+LCYCurrentDate.h"

@interface NSDate ()

@end

@implementation NSDate (LCYCurrentDate)

// 获取当前时间
+ (NSDate *)getCurrentDate
{
    NSDate *date = [NSDate date];
    
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    
    NSInteger interval = [zone secondsFromGMTForDate: date];
    
    NSDate *localeDate = [date  dateByAddingTimeInterval: interval];
    
    return localeDate;
}


+ (NSString *)stringFromDate:(NSDate *)date
{
    // 如果时间为空
    if(date == nil)
    {
        return nil;
    }
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    NSString *strDate;
    if([[NSDate getCurrentDate] timeIntervalSinceDate:date] > 86400 * 2)
    {
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        strDate = [dateFormatter stringFromDate:[NSDate date]];
    }else if ([[NSDate getCurrentDate] timeIntervalSinceDate:date] > 86400)
    {
        [dateFormatter setDateFormat:@"HH:mm:ss"];
        strDate = [NSString stringWithFormat:@"昨天 %@", [dateFormatter stringFromDate:[NSDate date]]];
    }else
    {
        [dateFormatter setDateFormat:@"HH:mm:ss"];
        strDate = [NSString stringWithFormat:@"今天 %@", [dateFormatter stringFromDate:[NSDate date]]];
    }
    
    return strDate;
}

@end
